<?php
namespace app\house\model;
use app\BaseModel;
use think\facade\Db;



class AdminBanner extends BaseModel
{
    //定义表名
    protected $name = 'longbing_card_house_ad';
    /**
     * @param $query
     * 查询范围
     */
    public function scopeStatus($query, $status){
        $query->where('status', '>', $status);
    }
    /**
     * @param $dis
     * @return array
     * @throws \think\exception\DbException
     * 房产banner列表
     */
    public function bannerList($dis,$page = 10){
        $data = $this->where($dis)->status(-1)->order('top desc')->paginate($page)->toArray();
        $data['data'] = transImages($data['data'],['path']);
        return $data;
    }


    /**
     * @param $dis
     * 获取前段房产banner
     */
    public function bannerSelect($dis,$field='*'){
       $data = $this->where($dis)->field($field)->status(-1)->order('top desc,id desc')->limit(10)->select()->toArray();
       $data = transImagesOne($data,['path']);
       return $data;
    }


    /**
     * @param $data
     * @return int|string
     * 添加房产banner
     */
    public function bannerAdd($data){
        $data['create_time'] = time();
        $data['update_time'] = time();
        $data['status']      = 1;
        $res = $this->insert($data);
        return $res;
    }


    /**
     * @param $dis
     * @param $data
     * @return AdminCate
     * 编辑房产banner
     */
    public function bannerUpdate($dis,$data){
        $data['update_time'] = time();
        $res = $this->where($dis)->update($data);
        return $res;

    }


    /**
     * @param $dis
     * 房产banner详情
     */
    public function bannerInfo($dis){
        $data = $this->where($dis)->status(-1)->find();
        $data = !empty($data)?$data->toArray():$data;
        $data = transImages($data,['path']);
        return $data;
    }



}